<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport('joomla.application.component.view');
	
	class HizkimizkiViewMsgs extends JView
	{
		var $_option = null;
		
		function display($tpl = null){
						
			$this->assignRef('msg', "Some Error happend, try again!");
			$this->addJS();
			
			parent::display($tpl);
		}

		function addTranslation($tpl = null){

			$this->addJS();
			$this->addCSS();

			$model = &$this->getModel();

			$showlink = 0;
	    	//Add word in db via model
	        if($model->addTranslation()){
	        	$msg = "Translation proposed! Your translation proposal will be checked by an administrator before being published, thanks for your help! ";
	        	$showlink = 1;
	        }
	        else
	        	$msg = "Up! It seems that an error ocurred, try again later! Sorry!";
	        	
	        $this->assignRef('msg',$msg);
			
	        $this->assignRef('showlink',$showlink);

			parent::display($tpl);
		}

		function manageTranslation($tpl = null){

			$this->addJS();
			$this->addCSS();

			$model = &$this->getModel();

			$showlink = 0;
	    	//Add word in db via model
	        if($model->updateTranslation()){
	        	$msg = "Itzulpena eguneratua! Eskerrik asko! ";
	        	$showlink = 1;
	        }
	        else
	        	$msg = "Ups! Arazorenbat egon dela ematen du... barkatu!";
	        	
	        $this->assignRef('msg',$msg);
			
	        $this->assignRef('showlink',$showlink);

			parent::display($tpl);
		}

		function stateTranslation($tpl = null){

			$this->addJS();
			$this->addCSS();

			$model = &$this->getModel();

			$showlink = 0;
	    	//Add word in db via model
	        if($model->stateTranslation()){
	        	$msg = "Itzulpena eguneratua! Eskerrik asko! ";
	        	$showlink = 1;
	        }
	        else
	        	$msg = "Ups! Arazorenbat egon dela ematen du... barkatu!";
	        	
	        $this->assignRef('msg',$msg);
			
	        $this->assignRef('showlink',$showlink);

			parent::display($tpl);
		}
		
		function addJS(){
			$option=JRequest::getCmd('option');
			
			$document = &JFactory::getDocument();
			$document->addScript( 'components/'.$option.'/js/jquery-1.9.1.min.js' );
			$document->addScript( 'components/'.$option.'/js/hizkimizkiForm.js' );
			$document->addScript( 'components/'.$option.'/js/jquery-ui-1.10.0.custom.min.js' );
			?>
			<script>
				<?php
				echo "\n var ERROR_MSG='".JText::_('ERROR_MSG')."';";
				?>
			</script>
			<?php
		}

		function addCSS(){
			$option = JRequest::getCmd('option');

			$document = &JFactory::getDocument();
			$document->addStyleSheet('components/'.$option.'/css/hizki.css');
			$document->addStyleSheet('components/'.$option.'/css/jquery-ui-1.10.0.custom.min.css');
		}
		
	}
?>